package com.app.server.impl;

import com.app.mapper.AnimalMapMapper;
import com.app.mapper.AnimalMapMapper;
import com.app.model.AnimalMapModel;
import com.app.model.AnimalMapModel;
import com.app.server.AnimalMapService;
import com.app.utils.StringTool;
import com.app.vo.AnimalMapVo;
import com.app.vo.AnimalMapVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnimalMapServiceImpl extends ServiceImpl<AnimalMapMapper, AnimalMapModel>implements AnimalMapService {
    @Autowired
    private AnimalMapMapper animalMapMapper;
    @Override
    public AnimalMapVo getAnimalMapList(Integer page, Integer limit,String name) {
        Page<AnimalMapModel> page1 = new Page<>(page, limit);

        QueryWrapper<AnimalMapModel> qw =new QueryWrapper<>();
        if (StringTool.isNotEmpty(name)){
            qw.like("name",name);
        }

        Page<AnimalMapModel> animalMapPage = animalMapMapper.selectPage(page1, qw);
        List<AnimalMapModel> animalMapList = animalMapPage.getRecords();

        long count = animalMapPage.getTotal();
        AnimalMapVo animalMapVo = new AnimalMapVo();
        animalMapVo.setList(animalMapList);
        animalMapVo.setCount((int) count);
        return animalMapVo;
    }
}
